package com.itservice.supporter_navi.utilities;

import java.util.ArrayList;

import android.util.Log;

import com.google.android.gcm.server.Message;
import com.google.android.gcm.server.MulticastResult;
import com.google.android.gcm.server.Sender;


public class GCMSendMsg {
	public static void SendMsg(String[] regIds , String msg) {
		try{
			String sendMessage = msg;
			Log.i(CommonUtilities.LOG_TAG,"SendMessage:"+sendMessage);

		    ArrayList<String> devices = new ArrayList<String>();
		    for(int i=0;i<regIds.length;i++){
		    	devices.add(regIds[i]);
		    	Log.i(CommonUtilities.LOG_TAG,"SendID:"+regIds[i]);
		    }
		    Sender sender = new Sender( CommonUtilities.API_KEY );
		    Message message = new Message.Builder().addData("message", sendMessage).collapseKey("suponavi").timeToLive(CommonUtilities.SEND_GCM_TIME_TO_LIVE).build();


		    // リザルトには5回のリトライ送信でGCMサーバが利用できなかった時の結果応答を保存します。
		    MulticastResult result = sender.send(message, devices, 5);

		} catch (Exception e){
			System.out.println(e);
		}
	}
}
